Ext.ns("Portal.teleScreen");

Ext.apply(Portal.teleScreen, {


    //functie de stergere / editare inregistrare
    actionSched: function() {
        var iRec = 0,oWind, iRecContact = 0;
        var op = (this.action) ? this.action : "edit"
        var oGrid = Ext.getCmp(Portal.teleScreen.id).find("itemId", "schedGrid")[0];
        var oGridContact = Ext.getCmp(Portal.teleScreen.id).find("itemId", "contactGrid")[0];
        //var oLogGrid = Ext.getCmp(Portal.teleScreen.id).find("itemId", "logGrid")[0];
        var oLogGridGeneral = Ext.getCmp(Portal.teleScreen.id).find("itemId", "oLogGridGeneral")[0];


        if (op === "edit") {
            if (oGrid.selModel.getCount() != 1) {
                Portal.events.throwInformation("Selectati o inregistrare !");
                return;
            }
            iRec = oGrid.selModel.getSelected().id;
        }

        if (op === "add") {
            if (oGridContact.selModel.getCount() != 1) {
                Portal.events.throwInformation("Selectati un contact !");
                return;
            }
            iRecContact = oGridContact.selModel.getSelected().id;
        }
        //constructie formular
        var oFpAdd = new Ext.FormPanel({
            autoHeight: true, //inaltimea formului va da inaltimea ferestrei
            labelWidth: 160,
            frame : true,
            bodyStyle: {
                padding : "5px"
            },
            layout: "form",
            defaults: {
                anchor: "90%",
                xtype: "textfield",
                allowBlank: false
            },
            items: [
                {
                    name: "tsched_name",
                    fieldLabel: "Nume"
                },
                {
                    name: "tsched_phone",
                    fieldLabel: "Telefon"
                },
                {
                    vtype: "email",
                    name: "tsched_email",
                    fieldLabel: "Email"
                },
                {
                    fieldLabel: "Functie",
                    name : "position_id",
                    itemId : "position_id",
                    xtype : "uxFCombo",
                    easyConfig: {
                        readerRoot : "rows",
                        baseParams: {
                            table: "position"
                        },
                        proxyUrl: "data/bringObject/"
                    }
                } ,
                {
                    name: "tsched_place",
                    fieldLabel: "Loc intalnire"
                },
                {
                    xtype:"xdatetime" ,
                    name:"tsched_date"  ,
                    fieldLabel:"Data intalnire"  ,
                    anchor:"-18" ,
                    timeFormat:"H:i:s"   ,
                    timeConfig: {
                        altFormats:"H:i:s" ,
                        allowBlank: true
                    } ,
                    dateFormat:"Y-m-d" ,
                    dateConfig: {
                        altFormats:"Y-m-d|Y-n-d"  ,
                        allowBlank: true
                    }
                }   ,

                {
                    name: "tsched_company",
                    fieldLabel: "Firma" ,
                    allowBlank: true
                },
                {
                    name: "tsched_company_adr",
                    fieldLabel: "Adresa firma",
                    allowBlank: true
                },
                {
                    name : "tsched_id",
                    xtype : "hidden",
                    value : iRec
                } ,
                {
                    name : "IdContact",
                    xtype : "hidden",
                    value : iRecContact
                }
            ],
            buttons: [
                {
                    text: "Salvare",
                    handler: function() {

                        if (!oFpAdd.getForm().isValid()) {
                            return;
                        }

                        oFpAdd.getForm().submit({
                            url: "teleSched/operation",
                            success: function(form, response) {
                                //oLogGrid.store.load();
                                oGrid.store.reload();
                                oLogGridGeneral.store.reload();
                                oWind.close();
                            }
                        });
                    }
                }
            ]
        });

        //constructie fereastra
        oWind = new Ext.Window({
            title: (op === "edit") ? "Editare inregistrare" : "Adaugare inregistrare",
            width: 450,
            layout: "fit",
            modal: true,
            closeAction: "close",
            items: [oFpAdd]
        }).show();

        //daca este editare de inregistrare atunci se aduc datele acestei inregistrari
        if (op === "edit") {
            oFpAdd.on("afterlayout", function() {
                        Ext.Ajax.request({
                            url: "teleSched/getRecord",
                            params: {
                                iRec :  iRec
                            },
                            success: function(response) {
                                var oRes = Ext.decode(response.responseText);
                                var oData = oRes.data;
                                fnCompleteForm(oFpAdd, oData);  //vezi utils.js
                            }})
                    }, this, {single: true});
        }
    }  ,

    /**
     * Functie care face un call ajax si completeaza taburile pentru telemarketing
     */
    getTele : function() {
        if (this.selModel.getCount() == 1) {

            //cautare id campanie
            var IdCampaign = Ext.getCmp(Portal.teleScreen.id).find("itemId", "contactGrid")[0].getTopToolbar().find("itemId", "IdCampaign")[0].getValue();

            //selectie record grid contacte
            var selection = this.selModel.getSelected();

            //cautare griduri  cu intrebari
            var answerGrid = Ext.getCmp(Portal.teleScreen.id).find("itemId", "answerGrid")[0];
            var answerGridFree = Ext.getCmp(Portal.teleScreen.id).find("itemId", "answerGridFree")[0];

            answerGrid.store.reload({
                params  : {
                    IdContact: selection.id,  IdCampaign :   IdCampaign
                }
            });
            answerGridFree.store.reload({
                params  : {
                    IdContact: selection.id,  IdCampaign :   IdCampaign
                }
            });

        }
    },


    //Transfer contacte la un user
    transfToUser: function() {
        var gridContacte = Ext.getCmp(Portal.teleScreen.id).getComponent("contactGrid");
        if (gridContacte.selModel.getCount() >= 1) {
            var selection = gridContacte.selModel.getSelections();
            var prez = [];
            for (var i = 0; i < gridContacte.selModel.getCount(); i++) {
                prez.push(selection[i].id);
            }
        }
        else {
            Portal.events.throwWarning("Selectati cel putin un contact");
            return;
        }

        var fpUpload = new Ext.FormPanel({
            layout: "form",
            autoHeight: true,
            frame: true,
            items: [
                {
                    fieldLabel : "User",
                    anchor: "90%",
                    xtype : "uxFCombo",
                    allowBlank: false,
                    editable : true,
                    name : "user_id",
                    easyConfig: {
                        baseParams : {
                            activ : "1"
                        } ,
                        readerFields: [
                            { name : "id",  mapping : "user_id"  },
                            { name : "name", mapping : "name" }
                        ]  ,
                        proxyUrl:  "user/getData"
                    }
                }
            ],
            buttons: [
                {
                    text: "Salveaza",
                    handler: function() {
                        if (fpUpload.getForm().isValid()) {
                            fpUpload.getForm().submit({
                                url: "tele/transferContact" ,
                                params: {
                                    contacts: Ext.encode(prez)
                                },
                                success: function(form, action, o) {
                                    wUpload.close();
                                    gridContacte.store.reload();
                                }
                            });
                        }
                    }
                }
            ]
        });

        var wUpload = new Ext.Window({
            width: 400,
            layout: "fit",
            title: "Transfera la user",
            modal :true,
            closable: true,
            closeAction: "close",
            frame: true,
            items: [fpUpload]
        });
        wUpload.show();
    }
});

Ext.apply(Portal.teleScreen, {

    id: "idTabteleScreen",
    exec: function() {

        if (!Ext.getCmp(Portal.teleScreen.id)) {


            var oCmLogGeneral = new Ext.grid.ColumnModel({
                columns: [
                    {
                        header: "Nume",
                        dataIndex: "LastName"
                    },
                    {
                        header: "Prenume",
                        dataIndex: "FirstName"
                    },
                    {
                        header: "Companie",
                        dataIndex: "CompanyName"
                    },
                    {
                        header: "Operatie",
                        dataIndex: "tl_operation_text"
                    },
                    {
                        header: "User",
                        dataIndex: "name"
                    },
                    {
                        header: "Data",
                        dataIndex: "tl_date"
                    } ,
                    {
                        header : "Operatie",
                        dataIndex: "tl_operation" ,
                        renderer : Portal.renderer.teleLog,
                        width  :40
                    }
                ],
                defaults: {
                    sortable: true ,
                    renderer : Portal.renderer.toolTip
                }
            });

            var oLogGridGeneral = new Ext.ux.fastGrid({
                xtype: "uxFGrid",
                layout: "fit",
                listeners: {
                    activate: function(tab) {
                        oLogGridGeneral.store.reload();
                    }
                },
                title : "Log general",
                itemId: "logGridGeneral",
                gridConfig: {
                    sortField : "tl_date" ,
                    sortDir : "DESC",
                    autoLoad : false,
                    url: "tele/getLogGeneral" ,
                    fields: ["tl_id", "name", "tl_date", "tl_operation_text", "tl_operation","LastName","FirstName","CompanyName"]
                },
                cm: oCmLogGeneral  ,
                tbar : ["-"]
            });


            var teleFilter = new Ext.form.FormPanel({
                frame: true,
                buttonAlign: "center",
                title: "Filtre",
                itemId : "teleFilter",
                layout: "form",
                items : [
                    {
                        layout: "column",
                        defaults: {
                            layout: "form",
                            columnWidth: 0.5,
                            defaults :  { anchor: "95%", xtype: "textfield",  listWidth : 400,  itemCls: "x-form-item-filter" }
                        },
                        items :[
                            {
                                items : [
                                    { name: "LastName", fieldLabel: "Nume " },
                                    { name: "FirstName", fieldLabel: "Prenume " }  ,
                                    {
                                        fieldLabel: 'Judet',
                                        xtype: "uxFCombo",
                                        anchor: "70%",
                                        name: "IdCounty",
                                        itemId: "county",
                                        forceSelection: false,
                                        minChars: 2,
                                        easyConfig: {
                                            baseParams: {},
                                            proxyUrl: 'County/GetCounty/'
                                        },
                                        listeners: {
                                            select:  function (combo, value) {
                                                cbCity = teleFilter.find("itemId", "city")[0];
                                                cbCity.setValue('');
                                                cbCity.setDisabled(false);
                                                cbCity.store.load({ params : {
                                                    county_id : combo.getValue()
                                                }
                                                });
                                            }
                                        } ,
                                        getListParent: function () {
                                            return this.el.up('.x-menu');
                                        }
                                    }
                                    ,
                                    {
                                        fieldLabel: 'City',
                                        xtype: "uxFCombo",
                                        anchor: "70%",
                                        name: "IdCity",
                                        itemId: "city",
                                        disabled : true,
                                        forceSelection: false,
                                        minChars: 2,
                                        easyConfig: {
                                            baseParams: {},
                                            proxyUrl: 'City/GetCity/'
                                        }
                                    }
                                ]
                            } ,
                            {
                                items :[
                                    {
                                        fieldLabel: 'Companie',
                                        xtype: "uxFCombo",
                                        anchor: "70%",
                                        name: "IdCompany",
                                        itemId: "company",
                                        forceSelection: false,
                                        minChars: 2,
                                        easyConfig: {
                                            readerFields: [
                                                { name : "Id",  mapping : "IdCompany"  },
                                                { name : "Name", mapping : "CompanyName" }
                                            ]  ,
                                            baseParams: {},
                                            proxyUrl: 'Company/GetCompany/'
                                        }
                                    },
                                    {
                                        fieldLabel: 'Functie',
                                        xtype: "uxFCombo",
                                        anchor: "70%",
                                        name: "IdPosition",
                                        itemId: "position",
                                        forceSelection: false,
                                        minChars: 2,
                                        easyConfig: {
                                            baseParams: {},
                                            proxyUrl: 'Position/GetPosition/'
                                        },
                                        listeners: {
                                            select:  function (combo, value) {
                                                cbSubPos = teleFilter.find("itemId", "subposition")[0];
                                                cbSubPos.setValue('');
                                                cbSubPos.setDisabled(false);
                                                cbSubPos.store.load({ params : {
                                                    position_id : combo.getValue()
                                                }
                                                });
                                            }
                                        } ,
                                        getListParent: function () {
                                            return this.el.up('.x-menu');
                                        }
                                    }
                                    ,
                                    {
                                        fieldLabel: 'Subfunctie',
                                        xtype: "uxFCombo",
                                        anchor: "70%",
                                        name: "IdSubposition",
                                        itemId: "subposition",
                                        disabled : true,
                                        forceSelection: false,
                                        minChars: 2,
                                        easyConfig: {
                                            baseParams: {},
                                            proxyUrl: 'Subposition/GetSubposition/'
                                        }
                                    }  ,
                                    {
                                        xtype: 'compositefield',
                                        fieldLabel: 'Status',
                                        msgTarget : 'side',
                                        items: [
                                            {
                                                xtype : "uxFCombo",
                                                editable : false,
                                                name : "StatusType",
                                                flex : 1,
                                                easyConfig: {
                                                    mode : "local",
                                                    localData: [
                                                        ['1', '='],
                                                        ['0', 'Diferit']
                                                    ]
                                                }
                                            } ,
                                            {
                                                name: 'IdStatus',
                                                hiddenName: 'IdStatus',
                                                flex : 2,
                                                editable: false,
                                                xtype : "lovcombo" ,
                                                triggerAction : "all",
                                                id : Portal.teleScreen.id + "_status",
                                                store: new Ext.data.JsonStore({
                                                    url: 'TStatus/GetTStatus',
                                                    root: 'Records',
                                                    baseParams: {
                                                        empty: ""
                                                    },
                                                    fields: [
                                                        { name : "id",  mapping : "IdTStatus"  },
                                                        { name : "name", mapping : "TStatusName" }
                                                    ]
                                                }),
                                                mode: 'remote',
                                                displayField: 'name',
                                                valueField: 'id' ,
                                                listeners : {
                                                    beforequery : function(combo) {
                                                        var campaign = oContactGrid.getTopToolbar().getComponent("IdCampaign");
                                                        this.store.baseParams.IdCampaign = campaign.getValue();
                                                    }
                                                }
                                            }
                                            /*


                                             {
                                             fieldLabel : "Status",
                                             xtype : "uxFCombo",
                                             name : "ts_id",
                                             listWidth : 200,
                                             listeners : {
                                             beforequery : function(combo) {
                                             var mailer = oContactGrid.getTopToolbar().getComponent("mailer_id");
                                             var record = mailer.findRecord("id", mailer.getValue());
                                             this.store.baseParams.client_id = record.data.client_id;
                                             }
                                             },
                                             easyConfig: {
                                             readerRoot : "data",
                                             readerFields: [
                                             { name : "id",  mapping : "ts_id"  },
                                             { name : "name", mapping : "ts_name" }
                                             ]  ,
                                             baseParams: {
                                             ts_active: "1"
                                             },
                                             proxyUrl: "teleStatus/getData/"
                                             }
                                             }   */
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ],
                buttons: [
                    {
                        text: 'Cauta',
                        iconCls: 'icon-fugue-binocular',
                        handler: function() {
                            var campaign = oContactGrid.getTopToolbar().getComponent("IdCampaign");
                            if (campaign.getValue() == "") {
                                Portal.events.throwWarning("Selecatati o campanie");
                                return;
                            }
                            oContactGrid.store.reload({
                                params : teleFilter.getForm().getValues(false)
                            });
                        }
                    },
                    {
                        text: 'Reset',
                        iconCls: 'icon-link-break',
                        handler: function() {
                            teleFilter.getForm().reset();
                            oContactGrid.store.on('beforeload',
                                    function(store, options) {
                                        options.params = teleFilter.getForm().getValues(false);
                                    });
                            oContactGrid.store.reload();
                        }
                    }
                ]
            });


            var oCmSched = new Ext.grid.ColumnModel({
                columns: [
                    {
                        name: "tsched_id",
                        header: "ID"  ,
                        width : 50
                    },
                    {
                        header: "Nume",
                        dataIndex: "tsched_name",
                        width: 200
                    },
                    {
                        header: "Telefon",
                        dataIndex: "tsched_phone"
                    },
                    {
                        header: "Email",
                        dataIndex: "tsched_email"
                    },
                    {
                        header: "Functie",
                        dataIndex: "name"
                    },
                    {
                        header: "Loc intalnire",
                        dataIndex: "tsched_place"
                    }  ,
                    {
                        header: "Data intalnire",
                        dataIndex: "tsched_date"
                    } ,
                    {
                        dataIndex: "tsched_company",
                        header: "Firma"
                    },
                    {
                        dataIndex: "tsched_company_adr",
                        header: "Adresa firma"
                    }
                ],
                defaults: {
                    sortable: true,
                    renderer : Portal.renderer.tooltipRenderer
                }
            });

            var oSchedGrid = new Ext.ux.fastGrid({
                xtype: "uxFGrid",
                layout: "fit",
                title : "Programari",
                itemId: "schedGrid",
                gridConfig: {
                    autoLoad : false,
                    sortField : "tsched_date" ,
                    sortDir : "DESC" ,
                    url: "teleSched/getData" ,
                    fields: ["tsched_id", "tsched_name", "tsched_phone", "tsched_email", "name","tsched_place","tsched_date", "tsched_company_adr", "tsched_company"]
                },
                cm: oCmSched,
                tbar: [
                    {
                        text: "Adauga",
                        iconCls: "icon-fugue-plus-circle",
                        action: "add",
                        handler: Portal.teleScreen.actionSched
                    },
                    "-",
                    {
                        text: "Editeaza",
                        iconCls: "icon-fugue-pencil",
                        action: "edit",
                        handler: Portal.teleScreen.actionSched
                    }
                ],
                listeners: {
                    "rowdblclick": Portal.teleScreen.actionSched
                }
            });

            oSchedGrid.store.on("beforeload", function() {
                if (oContactGrid.selModel.getCount() == 1) {
                    oSchedGrid.store.baseParams.IdContact = oContactGrid.selModel.getSelected().id;
                }
            });

            //column model grid intrebari cu raspuns multiplu
            var oCmQuestion = new Ext.grid.ColumnModel({
                columns: [
                         {
                        header: "Nr",
                        dataIndex: "IdQuestion"
                    },
                    {
                        header: "Intrebare",
                        dataIndex: "QuestionName"   ,
                        width   : 500
                    },
                    {
                        header: "Raspuns",
                        dataIndex: "AnswerName",
                        width: 150,
                        css:"background-color: #eefffe !important;",
                        editor : new Ext.ux.fastCombo.Combo({
                            xtype: "uxFCombo",
                            editable: false,
                            easyConfig: {
                                baseParams : {
                                    //tq_active : ""
                                }  ,
                                readerFields: [
                                    { name : "Id",  mapping : "IdAnswer"  },
                                    { name : "Name", mapping : "AnswerName" }
                                ]  ,
                                proxyUrl: "TQuestion/GetAnswerByIdQuestion/"
                            }   ,
                            listeners : {
                                beforequery : function(combo, record, rowIndex) {
                                    this.store.baseParams.IdQuestion = oQuestionGrid.selModel.getSelected().id;
                                } ,
                                blur : function(combo, record, rowIndex) {
                                    combo.store.removeAll();
                                    combo.lastQuery = null;
                                }
                            }
                        })
                    } ,
                    {
                        header: "Data",
                        dataIndex: "ta_date"   ,
                        width   : 100
                    }
                ],
                defaults: {
                    sortable: true
                }
            });

            //grid intrebari
            var oQuestionGrid = new Ext.ux.fastEditorGrid({
                layout: "fit",
                itemId: "answerGrid",
                title : "Intrebari",
                clicksToEdit: 1,
                flex : 1,
                gridConfig: {
                    storeBaseParams : {
                        IdContact : 0
                    },
                    autoLoad : false ,
                    sortField : "QuestionName" ,
                    url: "TQuestion/GetAnswerByContact/" ,
                    fields: ["IdQuestion", "QuestionName", "AnswerName"]
                },
                cm: oCmQuestion,
                listeners: {
                    "beforeedit": function (e) {
                        if (oContactGrid.selModel.getCount() == 0) {
                            Portal.events.throwInformation("Selectati un contact !");
                            e.record.reject();
                            return false;
                        }
                    }  ,
                    "afteredit": function (e) {
                        oQuestionGrid.store.reload();
                    }
                }
            });

            oQuestionGrid.store.on("beforeload", function() {
                if (oContactGrid.selModel.getCount() == 1) {
                    oQuestionGrid.store.baseParams.IdContact = oContactGrid.selModel.getSelected().id;
                }
            });


            ////////////////////

            //column model grid raspunsuri libere
            var oCmQuestionFree = new Ext.grid.ColumnModel({
                columns: [
                    {
                        header: "Nr",
                        dataIndex: "IdFQuestion",
                        width: 40
                    },
                    {
                        header: "Intrebare",
                        dataIndex: "FQuestionName"   ,
                        width   : 500
                    },
                    {
                        header: "Raspuns",
                        dataIndex: "FAnswerName",
                        width: 200,
                        css:"background-color: #eefffe !important;",
                        editor : new Ext.form.TextField({     })
                    } ,
                    {
                        header: "Data",
                        dataIndex: "taf_date"   ,
                        width   : 100
                    }
                ],
                defaults: {
                    sortable: true,
                    renderer : Portal.renderer.tooltipRenderer
                }
            });
            //grid raspinsuri libere
            var oQuestionGridFree = new Ext.ux.fastEditorGrid({
                layout: "fit",
                itemId: "answerGridFree",
                title : "Intrebari cu raspuns liber",
                clicksToEdit: 1,
                flex : 1,
                gridConfig: {
                    storeBaseParams : {
                        IdContact : 0
                    },
                    autoLoad : false ,
                    //sortField : "tqf_name" ,
                    url: "TQuestion/GetFreeAnswerByContact/" ,
                    fields: ["IdFAnswer", "FanswerName", "FQuestionName","IdFQuestion","taf_date"]
                },
                cm: oCmQuestionFree,
                listeners: {
                    "beforeedit": function (e) {
                        if (oContactGrid.selModel.getCount() == 0) {
                            Portal.events.throwInformation("Selectati un contact !");
                            e.record.reject();
                            return false;
                        }
                    }  ,
                    "afteredit": function (e) {
                        oQuestionGridFree.store.reload();
                    }
                }
            });

            oQuestionGridFree.store.on("beforeload", function() {
                if (oQuestionGridFree.selModel.getCount() == 1) {
                    oQuestionGridFree.store.baseParams.IdContact = oContactGrid.selModel.getSelected().id;
                }
            });


            var smContact = new Ext.grid.CheckboxSelectionModel({
                singleSelect : (Portal.user_role == "user" )
            });

            //column model grid contacte
            var oCmContact = new Ext.grid.ColumnModel({
                columns: [
                    smContact,
                    {
                        header: "Nume",
                        dataIndex: "LastName",
                        renderer: Portal.renderer.sex
                    },
                    {
                        header: "Prenume",
                        dataIndex: "FirstName"
                    },
                    {
                        header: "Companie",
                        dataIndex: "CompanyName" ,
                        renderer : Portal.renderer.campaignNameType
                    } ,
                    {
                        header: "Status",
                        dataIndex: "TStatusName"
                    },
                    {
                        header: "Telefon",
                        dataIndex: "PhoneNumber"
                    },
                    {
                        header: "Mobil",
                        dataIndex: "MobilNumber"
                    },
                    {
                        header: "User Alocat",
                        dataIndex: "name",
                        hidden : (Portal.user_role == "user")
                    }
                ],
                defaults: {
                    sortable: true ,
                    renderer : Portal.renderer.tooltipRenderer
                }
            });

            //grid contacte
            var oContactGrid = new Ext.ux.fastGrid({
                xtype: "uxFGrid",
                flex  : 1,
                itemId: "contactGrid",
                sm : smContact,
                gridConfig: {
                    itemNr : true,
                    autoLoad : false,
                    url: 'Contact/GetContactByCampaign',
                    fields: ['IdContact', 'LastName', 'FirstName','CompanyName','PhoneNumber','MobilNumber','TStatusName']
                },
                cm: oCmContact,
                tbar: [
                    {
                        hidden : (Portal.user_role == "user")  ,
                        iconCls: "icon-user-go",
                        tooltip : "Transfera la user contactele selectate",
                        handler: Portal.teleScreen.transfToUser
                    } ,
                    "-",
                    {
                        fieldLabel : "Campanie",
                        anchor: '90%',
                        xtype : "uxFCombo",
                        allowBlank: false,
                        editable : true,
                        name : "IdCampaign",
                        itemId : "IdCampaign",
                        easyConfig: {
                            baseParams : {
                                activ : "1"
                            } ,
                            readerFields: [
                                { name : "Id",  mapping : "Id"  },
                                { name : "Name", mapping : "Name" }
                            ]  ,
                            proxyUrl:  'Campaign/GetCampaign'
                        } ,
                        listeners : {
                            select : function(combo, record, rowIndex) {
                                teleFilter.getForm().reset();

                                //se resteaza valorile din storul comboboxului unde sunt tinute statusurile campaniei; la un nou select se actualizeaza lista de statusuri
                                var status = Ext.getCmp(Portal.teleScreen.id + "_status");
                                status.store.removeAll();
                                //la urmatoarea selectie a comboboxului acesta isi va lua datele de pe server
                                status.lastQuery = null;
                                //se actualizeaza gidul de contacte , conform campaniei selectate
                                oContactGrid.store.reload({
                                    params  : {
                                        IdCampaign : record.data.Id //    combo.getValue()
                                    }
                                });

                                oLogGridGeneral.store.reload({
                                    params  : {
                                        IdCampaign : record.data.Id
                                    }
                                });
                            }
                        }
                    }
                ] ,
                listeners : {
                    "rowclick" :  Portal.teleScreen.getTele
                }
            });

            //creare tab ce contine gridul
            var oNomTab = new Ext.Panel({
                title: "Telemarketing",
                id: Portal.teleScreen.id,
                iconCls: "icon-telephone",
                closable: true,
                layout: {
                    type: "hbox",
                    pack: "start",
                    align: "stretch"
                },
                items: [oContactGrid, {
                    xtype : "tabpanel",
                    flex : 1,
                    activeTab : 0,
                    items : [
                        teleFilter,
                        {
                            title : "Intrebari",
                            layout: {
                                type: 'vbox',
                                pack: 'start',
                                align: 'stretch'
                            },
                            items : [oQuestionGrid, oQuestionGridFree]
                        },
                        oSchedGrid ,
                        oLogGridGeneral
                    ]
                }]
            });

            //adaugare tab la tabpanel-ul principal
            Portal.oCenterRegion.add(oNomTab);
            Portal.oCenterRegion.doLayout();
        }
        //activare tab
        Portal.oCenterRegion.setActiveTab(Portal.teleScreen.id);
    }
});